﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using md.imi.membrane.constants;
using md.imi.membranes.objects.membranes;

namespace md.imi.membranes.gui.Editor
{
    public partial class MembraneEdit : Form
    {
        private MembranesTree mMembrane;

        public MembraneEdit()
        {
            InitializeComponent();
        }

        public MembraneEdit(string parentLabel, MembranesTree membrane) : this ()
        {
            mMembrane = membrane;

            lblInfo.Text = String.Format("For parent membrane [{0}]", parentLabel);
            tbLabel.Text = mMembrane.Label;

            rbNegative.Checked  = mMembrane.Charge == Charge.Negative;
            rbNeutral.Checked   = mMembrane.Charge == Charge.Neutral;
            rbPositive.Checked  = mMembrane.Charge == Charge.Positive;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            errorProvider.Clear();

            if (tbLabel.Text.Trim().Length == 0)
            {
                errorProvider.SetError(tbLabel, "Membrane label cannot be an empty string" );
                return;
            }

            DialogResult = DialogResult.OK;
        }


        public MembranesTree GetData()
        {
            mMembrane.Label = tbLabel.Text.Trim();
            mMembrane.Charge = (rbNegative.Checked
                                    ? Charge.Negative
                                    : (rbPositive.Checked ? Charge.Positive : Charge.Neutral));
            return mMembrane;
        }

    }
}
